layui.config({
    base : "/js/"
}).extend({
    "address" : "address"
})


layui.use(['form','layer','upload','laydate','layedit','address'],function(){
        var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery;
    var upload = layui.upload;
    var address = layui.address;
    var merchantDesc; //富文本编辑器

    //获取省信息
    address.provinces();


    //富文本编辑器
    layui.use('layedit', function(){
        var layedit = layui.layedit;
        layedit.set({
            uploadImage: {
                url: '/upload/editPicUpload' //接口url
                ,type: 'post' //默认post
            }
        });
        merchantDesc=layedit.build('merchantDesc',{
            height: 160 //设置编辑器高度
        }); //建立编辑器
    });

    //上传二维码
    upload.render({
        elem: '.userFaceBtn',
        field: 'uploadFile',//上传文件的名称，要和接口参数名称相同
        url: '/upload/pic',
        done: function(res, index, upload){
            if (res.code === 0) {
                layer.msg(res.msg);
                $("#uploadImage").attr("src",res.url);
                $("#qrcode").val(res.url);
            } else {
                layer.msg(res.msg);
            }
        }
    });

    //上传商家头像
    upload.render({
        elem: '.merchantFaceBtn',
        field: 'uploadFile',//上传文件的名称，要和接口参数名称相同
        url: '/upload/pic',
        done: function(res, index, upload){
            if (res.code === 0) {
                layer.msg(res.msg);
                $("#Image").attr("src",res.url);
                $("#logo").val(res.url);
            } else {
                layer.msg(res.msg);
            }
        }
    });
        //数据回显
    var request = GetRequest();
    $.get("/merchant/" + request.id,function (data) {
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
            console.log(data)
=======

>>>>>>> e56d4fde7fb05aad3d72b34f06dfab9c09b1d9b6
=======

>>>>>>> 9775937ee6a762cf0279a06e770d03c26fbe1797
=======

>>>>>>> 7becee1c494f66ac7c05c3fde0cf832425caf3ca
            $(".merchantId").val(data.merchantId),
            $(".merchantName").val(data.merchantName),
            $(".contactPhone").val(data.contactPhone),
            $('input[placeholder="请选择省"]').val(data.province),
            $('input[placeholder="请选择市"]').val(data.city),
            $('input[placeholder="请选择县/区"]').val(data.town),

            $('.qrcode').val(data.qrcode),
                $('#uploadImage').attr("src",data.qrcode),
            $('.logo').val(data.logo),
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
                $('#Image').attr("src",data.logo),
=======
                $('.Image').attr("src",data.logo),
>>>>>>> e56d4fde7fb05aad3d72b34f06dfab9c09b1d9b6
=======
                $('.Image').attr("src",data.logo),
>>>>>>> 9775937ee6a762cf0279a06e770d03c26fbe1797
=======
                $('.Image').attr("src",data.logo),
>>>>>>> 7becee1c494f66ac7c05c3fde0cf832425caf3ca
            $('.addressDetail').val(data.addressDetail),
            $('.merchantDesc').val(data.merchantDesc),
                merchantDesc=layui.layedit.build('merchantDesc',{
                    height: 160 //设置编辑器高度
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
                });

=======
                }),
>>>>>>> e56d4fde7fb05aad3d72b34f06dfab9c09b1d9b6
=======
                }),
>>>>>>> 9775937ee6a762cf0279a06e770d03c26fbe1797
=======
                }),
>>>>>>> 7becee1c494f66ac7c05c3fde0cf832425caf3ca
            $('.remarks').val(data.remarks)


    })






        form.on("submit(editMerchant)",function(data){
        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});

         $.post("/merchant/edit",{
             merchantId : $(".merchantId").val(),
             merchantName : $(".merchantName").val(),
             contactPhone : $(".contactPhone").val(),
             qrcode : data.field.qrcode,
             logo:data.field.logo,
             province:$('input[placeholder="请选择省"]').val(),
             city:$('input[placeholder="请选择市"]').val(),
             town:$('input[placeholder="请选择县/区"]').val(),
             addressDetail : data.field.addressDetail,
             remarks : data.field.remarks,
            // newsTime : submitTime,
             merchantDesc : layui.layedit.getContent(merchantDesc),
         },function(res){
         })
        setTimeout(function(){
            top.layer.close(index);
            top.layer.msg("用户修改成功！");
            layer.closeAll("iframe");
            //刷新父页面
            parent.location.reload();
        },2000);
        return false;
    })

<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD

=======
>>>>>>> e56d4fde7fb05aad3d72b34f06dfab9c09b1d9b6
=======
>>>>>>> 9775937ee6a762cf0279a06e770d03c26fbe1797
=======
>>>>>>> 7becee1c494f66ac7c05c3fde0cf832425caf3ca
    //获取路径中的参数
    function GetRequest() {
        var url = location.search;         //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            var strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }


<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======

>>>>>>> e56d4fde7fb05aad3d72b34f06dfab9c09b1d9b6
=======

>>>>>>> 9775937ee6a762cf0279a06e770d03c26fbe1797
=======

>>>>>>> 7becee1c494f66ac7c05c3fde0cf832425caf3ca
    //格式化时间
    function filterTime(val){
        if(val < 10){
            return "0" + val;
        }else{
            return val;
        }
    }
    //定时发布
    var time = new Date();
    var submitTime = time.getFullYear()+'-'+filterTime(time.getMonth()+1)+'-'+filterTime(time.getDate())+' '+filterTime(time.getHours())+':'+filterTime(time.getMinutes())+':'+filterTime(time.getSeconds());

})